package handler

import (
	"github.com/gin-gonic/gin"
	"live-broadcast/api/request"
	"live-broadcast/internal/dao"
	"live-broadcast/internal/model"
	"net/http"
)

func AddComment(c *gin.Context) {
	var req request.AddCommentForm
	var comment model.Comment
	//var lexicon model.Lexicon

	if err := c.ShouldBind(&req); err != nil {
		return
	}

	if req.UserId == 0 || req.Info == "" {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "验证失败",
			"data": nil,
		})
		return
	}

	comment = model.Comment{
		UserId: req.UserId,
		Info:   req.Info,
	}

	err := dao.AddFile(&comment)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "评论失败",
			"data": false,
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"msg":  "评论成功",
		"data": comment.Info,
	})

}
